package com.hsgene.authority.dto;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 权限详细信息
 *
 * @author wangbing
 * @version 1.0, 2018/11/1
 */
public class OperationPermissionTree implements Serializable, Comparable<OperationPermissionTree> {

    private static final long serialVersionUID = 2928791546460461877L;
    /**
     * 逻辑主键
     */
    private String id;

    /**
     * 权限名称
     */
    private String permissionName;

    /**
     * 父级节点
     */
    private String parentId;

    /**
     * 节点等级
     */
    private Integer level;

    /**
     * 节点排序位置
     */
    private Integer position;

    /**
     * 节点的小图标
     */
    private String icon;

    /**
     * 跳转的地址
     */
    private String url;

    /**
     * 接口请求方式
     */
    private String requestMethod;

    /**
     * 0-停用  1-启用
     */
    private Integer status;

    /**
     * 业务数据逻辑删除 0-代表未删除   1-代表删除
     */
    private Integer deleteFlag;

    /**
     * 备注
     */
    private String remarks;

    /**
     * 是否被选中（true：有此权限；false：无此权限）
     */
    private Boolean selected = Boolean.FALSE;

    /**
     * 是否通用权限（0：不是；1：是）当为1时，表示非主功能权限
     * 如某个添加页面上，需要请求API接口填充下拉框数据，当用户拥有此添加权限时，则默认用户也拥有下拉框API接口权限
     * 通用权限不会展示在权限分配上
     */
    private Integer commonFlag = 0;

    /**
     * 更新时间
     */
    private Date updateDateTime;

    /**
     * 下级权限列表；当此字段为空时，表示叶子节点权限
     */
    private List<OperationPermissionTree> childrenPermissions;

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof OperationPermissionTree)) {
            return false;
        }
        OperationPermissionTree other = (OperationPermissionTree) obj;

        return this.id.equals(other.id);
    }

    @Override
    public int hashCode() {
        return this.id.hashCode();
    }

    @Override
    public int compareTo(OperationPermissionTree o) {
        // 比较节点等级，越小等级越高
        if (this.level > o.level) {
            return -1;
        } else if (this.level < o.level) {
            return 1;
        }
        // 比较主功能节点，主功能节点优先
        if (this.commonFlag < o.commonFlag) {
            return 1;
        } else if (this.commonFlag > o.commonFlag) {
            return -1;
        }
        // 比较position
        if (this.position != null && o.position != null) {
            return this.position.compareTo(o.getPosition());
        }

        return 0;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getRequestMethod() {
        return requestMethod;
    }

    public void setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public List<OperationPermissionTree> getChildrenPermissions() {
        return childrenPermissions;
    }

    public void setChildrenPermissions(List<OperationPermissionTree> childrenPermissions) {
        this.childrenPermissions = childrenPermissions;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public Integer getCommonFlag() {
        return commonFlag;
    }

    public void setCommonFlag(Integer commonFlag) {
        this.commonFlag = commonFlag;
    }

    public Date getUpdateDateTime() {
        return updateDateTime;
    }

    public void setUpdateDateTime(Date updateDateTime) {
        this.updateDateTime = updateDateTime;
    }
}
